package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.PropertyInject;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.InjectType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.order.domain.Greenhouse;
import com.ruoyi.order.service.IGreenhouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 大棚管理Controller
 *
 * @author ruoyi
 * @date 2021-07-11
 */
@RestController
@RequestMapping("/system/greenhouse")
public class GreenhouseController extends BaseController
{
    @Autowired
    private IGreenhouseService greenhouseService;

    /**
     * 查询大棚管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:greenhouse:list')")
    @GetMapping("/list")
    public TableDataInfo list(Greenhouse greenhouse)
    {
        startPage();
        List<Greenhouse> list = greenhouseService.selectGreenhouseList(greenhouse);
        return getDataTable(list);
    }

    /**
     * 导出大棚管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:greenhouse:export')")
    @Log(title = "大棚管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Greenhouse greenhouse)
    {
        List<Greenhouse> list = greenhouseService.selectGreenhouseList(greenhouse);
        ExcelUtil<Greenhouse> util = new ExcelUtil<Greenhouse>(Greenhouse.class);
        return util.exportExcel(list, "大棚管理数据");
    }

    /**
     * 获取大棚管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:greenhouse:query')")
    @GetMapping(value = "/{greenhouseId}")
    public AjaxResult getInfo(@PathVariable("greenhouseId") Long greenhouseId)
    {
        return AjaxResult.success(greenhouseService.selectGreenhouseById(greenhouseId));
    }

    /**
     * 新增大棚管理
     */
    @PreAuthorize("@ss.hasPermi('system:greenhouse:add')")
    @Log(title = "大棚管理", businessType = BusinessType.INSERT)
    @PostMapping
    @PropertyInject(type = InjectType.Insert)
    public AjaxResult add(@RequestBody Greenhouse greenhouse)
    {
        return toAjax(greenhouseService.insertGreenhouse(greenhouse));
    }

    /**
     * 修改大棚管理
     */
    @PreAuthorize("@ss.hasPermi('system:greenhouse:edit')")
    @Log(title = "大棚管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @PropertyInject(type = InjectType.Update)
    public AjaxResult edit(@RequestBody Greenhouse greenhouse)
    {
        return toAjax(greenhouseService.updateGreenhouse(greenhouse));
    }

    /**
     * 删除大棚管理
     */
    @PreAuthorize("@ss.hasPermi('system:greenhouse:remove')")
    @Log(title = "大棚管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{greenhouseIds}")
    public AjaxResult remove(@PathVariable Long[] greenhouseIds)
    {
        return toAjax(greenhouseService.deleteGreenhouseByIds(greenhouseIds));
    }
}
